import request from "@/utils/request";

//按条件分页查看资源
type Common<T> = {
    code: string
    data: T
    mesg: string
    time: string

}

export type QueriedResult = {
    current: number
    hitCount?: false
    optimizeCountSql: boolean
    orders?: any[]
    pages?: number
    records: Resource[] | []
    searchCount?: boolean
    size: number
    total: number
}

export type Resource = {
    categoryId: number
    createdBy: string
    createTime: string
    description: string
    id: number
    name: string
    operatorId: number | null
    selected: boolean
    updateBy: string
    updateTime: string
    url: string
}

export type Condition = Partial<{
    id: number
    name: string
    startCreateTim: string
    url: string
    endCreateTime: string
    categoryId: number | ""
    current: number
    size: number
}>

export const getResourcesPages = (condition:Condition) => {
    return request<Common<QueriedResult>>({
        method: "post",
        url: "/boss/resource/getResourcePages",
        data: condition
    })
}

// 保存或更新资源
export const saveOrUpdate = (resource: Resource) => {
    return request<Common<boolean>>({
        method: "post",
        url: "/boss/resource/saveOrUpdate",
        data: resource
    })
}
//删除指定ID的资源
export const deleteResource = (id: number) => {
      return request({
        method:'delete',
        url: `/boss/resource/${id}`,
      })    
}

//获取指定ID的资源
export const getResourceById = (id: number) => {
    return request<Common<Resource>>({
        method: 'get',
        url: `/boss/resource/${id}`,
    })
}
    